﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracer.Kernels
{
    /// <summary>
    /// Beinhaltet den OpenCL Code der Kernel.
    /// </summary>
    partial class KernelInitCamera
    {
        private const string KERNEL_MAIN = "InitCamera";

        /*************
        *  
        *  Eingabe:
        *  resolution  Die Auflösung.
        *  apsect      Der Bildflächenaspekt.
        *  focus       Der Fokusfaktor.
        *  pos         Die Position der Kamera.
        *  xAxis       Die Blickwinkel X-Achse.
        *  yAxis       Die Blickwinkel Y-Achse.
        *  zAxis       Die Blickwinkel Z-Achse.
        *  
        * 
        *  Ausgabe:
        *  rayPos      Die Strahlenausgangsposition.    [i]
        *  rayDir      Die Strahlenvektor.              [i]
        *  
        *************/
        private const string KERNEL_SOURCE =  @"
            kernel void InitCamera(
                int2 resolution,
                float aspect,
                float focus,                        
                float4 pos,
                float4 xAxis,
                float4 yAxis,
                float4 zAxis,

                global write_only float4* rayPos,
                global write_only float4* rayDir
            )
            {
                int i = get_global_id(0);
                float4 dir = (xAxis * (2.0f * (((i % resolution.s0)/(float)resolution.s0 - 0.5f) * aspect)))
                             + (yAxis * (2.0f * ((i / resolution.s0)/(float)resolution.s1 - 0.5f)))
                             + (zAxis * focus);
                dir = normalize(dir);
                rayDir[i] = (float4)(dir.s0, dir.s1, dir.s2, 1.0002926f);
                rayPos[i] = pos;
            }
            ";
    }
}
